﻿using System;
using System.Windows.Forms;
using MobileCarManager.MobileControls.Styles;
using MobileCarManager.MobileControls.AppStylist.Stylists.Button;
using MobileCarManager.MobileControls.AppStylist.Stylists.View;

namespace MobileCarManager.MobileControls.AppStylist
{
  public partial class MainForm : Form
  {
    private string _fileName = string.Empty;

    public MainForm()
    {
      InitializeComponent();
    }

    private void OnLoad(object sender, EventArgs e)
    {
      tabControl.TabPages.Add(CreateTabPage(typeof(ButtonStylist)));
      tabControl.TabPages.Add(CreateTabPage(typeof(ViewStylist)));
    }

    private TabPage CreateTabPage(Type type)
    {
      UserControl control = (UserControl)Activator.CreateInstance(type);
      TabPage page = new TabPage((string)control.Tag);
      page.Controls.Add(control);
      control.Dock = DockStyle.Fill;
      return page;
    }

    private void openToolStripMenuItem_Click(object sender, EventArgs e)
    {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Multiselect = false;
      dlg.Filter = "Styles (*.xml)|*.xml";
      DialogResult result = dlg.ShowDialog();
      if (result == DialogResult.OK)
      {
        _fileName = dlg.FileName;
        StyleManager.Instance.LoadStyle(dlg.FileName);
      }
    }

    private void closeToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }

    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }

    private void saveasToolStripMenuItem_Click(object sender, EventArgs e)
    {
      SaveFileDialog dlg = new SaveFileDialog();
      dlg.Filter = "Styles (*.xml)|*.xml";
      if (DialogResult.OK == dlg.ShowDialog())
      {
        StyleManager.Instance.SaveStyles(dlg.FileName);
      }
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }
  }
}
